//
//  Game.m
//  PacIsBack
//
//  Created by Jérémy Brault on 21/01/10.
//  Copyright 2010 None. All rights reserved.
//

#import "Game.h"
#import "Player.h"

@implementation Game

@synthesize controller,player,currentBattle;

#pragma mark -
#pragma mark Contructors & Destructors

- (id)initGame {
	if (self = [super init]) {
		srand(time(NULL));
		GameViewController* gameController = [[GameViewController alloc] init];
		[self setController:gameController];
		[gameController release];
		Player* initialPlayer = [[Player alloc] initPlayer];
		[self setPlayer:initialPlayer];
		[initialPlayer release];
	}
	
	return self;
}

-(void) startGame{
	Battle* firstBattle = [[Battle alloc] initBattleWithPlayer:[self player] forGame:self];
	[self setCurrentBattle:firstBattle];
	[firstBattle release];
	[[self controller] launchBattle:[self currentBattle]];
}

- (void) fightLost:(id<BattleProtocol>) battle{
	
}

- (void) fightWon:(id<BattleProtocol>) battle{
	Battle* nextBattle = [[Battle alloc] initBattleWithPlayer:[self player] forGame:self];
	[self setCurrentBattle:nextBattle];
	[nextBattle release];
	[[self controller] launchBattle:[self currentBattle]];	
}

- (void) dealloc{
	[self setCurrentBattle:nil];
	[self setPlayer:nil];
	[self setController:nil];
	[super dealloc];
}

@end
